/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sun.ShipperProcessor;

import com.sun.Entity.Shippingorder;
import com.sun.Facade.ShippingorderFacadeLocal;
import exceptions.EstimatedShippingDateNotCalculatedException;
import exceptions.UnknownOrderException;
import java.util.Date;
import javax.ejb.EJB;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.ejb.Stateless;

/**
 *
 * @author test
 */
@WebService()
@Stateless()
public class ObtainShippingDateWS {

    @EJB
    private ShippingorderFacadeLocal shippingorderFacade;

    /**
     * Web service operation
     */
    @WebMethod(operationName = "ObtainShippingDate")
    public Date ObtainShippingDate(@WebParam(name = "OrderID") String OrderID) throws UnknownOrderException, EstimatedShippingDateNotCalculatedException {
        // Verification OrderID existance
        Shippingorder Order = shippingorderFacade.find(OrderID);
        if (Order == null) {
            throw new UnknownOrderException();
        }

        // Verification Estimatedshippingdate existance
        Date Estimatedshippingdate = Order.getEstimatedshippingdate();
        if (Estimatedshippingdate == null) {
            throw new EstimatedShippingDateNotCalculatedException();
        }

        return Estimatedshippingdate;
    }
}
